package com.lt.lumentracks.controller;


import com.lt.lumentracks.entity.po.Conversation;
import com.lt.lumentracks.entity.vo.chat.ConversationVO;
import com.lt.lumentracks.entity.vo.common.Result;
import com.lt.lumentracks.service.IConversationService;
import com.lt.lumentracks.service.common.ConversationMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 会话表 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-10-06
 */
@RestController
@RequestMapping("/conversation")
public class ConversationController {

    @Autowired
    private IConversationService iConversationService;
    @Autowired
    private ConversationMessageService conv_msgService;

    // 增（创建会话）
    @PostMapping("/add")
    public Result<Long> add(@RequestBody Conversation conversation){
        Long cid = iConversationService.addConversation(conversation, null);
        return Result.success(cid);
    }


    // 删（用户删除当前会话）
    @DeleteMapping("/del")
    public Result<String> del(@RequestParam("id") Long id){
        conv_msgService.removeConversation(id);
        return Result.success();
    }




    // 查（用户查询其加入的会话，返回会话列表）
    @GetMapping("/queryByUser")
    public Result<List<ConversationVO>> queryByUser(){
        List<ConversationVO> conversations = conv_msgService.queryByUser();
        return Result.success(conversations);
    }

    // 查（根据双方id，查询会话信息，仅限私聊）
    @GetMapping("/getWhisperConversation")
    public Result<ConversationVO> getWhisperConversation(@RequestParam("talker_uid") Integer talker_uid){
        ConversationVO vo = conv_msgService.getWhisperConversation(talker_uid);
        return Result.success(vo);
    }


}
